package com.xiaomili.halfsugar.adapter;

import android.content.Context;
import android.graphics.Bitmap;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.TextView;

import com.squareup.picasso.Picasso;
import com.xiaomili.halfsugar.R;
import com.xiaomili.halfsugar.bean.ImageBean;

import java.io.File;
import java.util.List;

/**
 * Created by Administrator on 2016/7/20 0020.
 */
public class PopAdapter extends BaseAdapter {

    private Context mContext;
    private List<ImageBean> mDatas;

    public PopAdapter(Context mContext, List<ImageBean> mDatas) {
        this.mContext = mContext;
        this.mDatas = mDatas;
    }



    @Override
    public int getCount() {
        Log.i("tag","whatfuck"+mDatas.size());
        return mDatas==null?0:mDatas.size();
    }

    @Override
    public Object getItem(int position) {
        return null;
    }

    @Override
    public long getItemId(int position) {
        return 0;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        ViewHolder holder = null;

        if (convertView==null){
            convertView = LayoutInflater.from(mContext).inflate(R.layout.item_pop, parent, false);
            holder = new ViewHolder(convertView);
            convertView.setTag(holder);
        }else{
            holder = (ViewHolder) convertView.getTag();
        }
        holder.tv_desc.setText(mDatas.get(position).getFolderName());
        Log.i("ffff","wwwww"+mDatas.get(position).getFolderName());
        holder.tv_count.setText(Integer.toString(mDatas.get(position).getImageCounts())+" 张");
        Picasso.with(mContext).load(new File(mDatas.get(position).getTopImagePath()))
                .resize(60,60)
                .config(Bitmap.Config.RGB_565)
                .centerInside()
                .into(holder.iv_pop);
        return convertView;
    }

    class ViewHolder{
        private ImageView iv_pop;
        private TextView tv_desc,tv_count;
        public ViewHolder(View itemView) {
            iv_pop = (ImageView) itemView.findViewById(R.id.iv_pop);
            tv_desc = (TextView) itemView.findViewById(R.id.tv_desc);
            tv_count = (TextView) itemView.findViewById(R.id.tv_count);
        }
    }
}
